{{- $count := default .Site.Params.relatedPostCount .Params.relatedPostCount -}}
{{- $relatedPosts := where (.Site.RegularPages.Related .) "Section" "in" .Site.Params.mainSections -}}
{{- if and $count $relatedPosts -}}
  {{- with ($relatedPosts | first $count) -}}
    <section class="related-posts row card component">
      <div class="card-header">
        <h2 class="card-title fs-4 my-2 text-surface">
          {{ i18n "related_posts" }}
        </h2>
      </div>
      <div class="card-body slide px-1">
        <div class="slide-inner row gx-0">
          {{- range . -}}
          <div class="col-12 col-md-6 col-lg-4 me-2">
            {{ partial "post/card" . }}
          </div>
        {{- end -}}
        </div>
        <button class="slide-control-left">
          <i class="fas fa-2x fa-chevron-circle-down" data-fa-transform="rotate-90"></i>
          <span class="visually-hidden">Left</span>
        </button>
        <button class="slide-control-right">
          <i class="fas fa-2x fa-chevron-circle-down" data-fa-transform="rotate-270"></i>
          <span class="visually-hidden">Right</span>
        </button>
      </div>
    </section>
  {{- end -}}
{{- end -}}
